﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepCultivation.API.AddliCation.AccountingunitsW;
using SheepCultivation.API.AddliCation.AddressW;
using SheepCultivation.API.AddliCation.DepartmentW;
using SheepCultivation.API.AddliCation.EnterPriseW;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Dto;
using SheepCultivation.Enum;
using static SheepCultivation.API.AddliCation.EnterPriseW.EnterPriseTreeSeachHandler;

namespace SheepCultivation.API.Controllers
{
    /// <summary>
    /// 第一周
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class SheepController : ControllerBase
    {
        public readonly IMediator mediator;

        public SheepController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 企业新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("EnterPriseAdd")]
        public async Task<Result> Handle(EnterPriseCreateCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 企业列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("EnterPriseList")]
        public async Task<Result> Handle(EnterPriseSeachCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 树形
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpPost("EnterPriseTree")]
        public async Task<Result> Handle(EnterPriseTreeSeachCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 部门新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [HttpPost("DePartmentAdd")]
        public async Task<Result> Handle(DepartmentCreateCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 部门显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("DePartmentList")]
        public async Task<Result> Handle(DepartmentSeachCommon request)
        {
            return await mediator.Send(request);

        }
        /// <summary>
        /// 省列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        [HttpPost("ProviceList")]
        public async Task<Result> Handle(ProvinceSeachCommon request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 市列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("CityList")]
        public async Task<Result> Handle(CitySeachCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 县列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("CountyList")]
        public async Task<Result> Handle(CountySeachCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 行业列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        /// 
        [HttpPost("IndustryList")]
        public async Task<Result> Handle(IndustrySeachCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 核算单位显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("AccountingunList")]
        public async Task<Result> Handle(AccountingUnitIdSeachCommon request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// 
        [HttpPost("FileUpLoad")]
        public IActionResult UploadFile(IFormFile file)
        {
            try
            {
                string fileName = Directory.GetCurrentDirectory() + @"\wwwroot\Img\" + file.FileName;
                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                };
                return Ok("http://localhost:5012/Img/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
